var updateWindow;
var loadDiv = null;
$(document).ready(function(){
	loadDiv = $("#loadDiv").loading({container:$("#updateDialog")});//初始化提示操作执行中
    //初始化验证
    updateUser();
	//初始化更新窗口
    updateWindow = $("#updateDialog");
    updateWindow.dialog({
        autoOpen: false,
        width: 450,
        height: 400,
        resizable: false,
        title: "修改用户信息",
        modal: true,
        buttons: {
            "保存": function () {
                $("#updateUserForm").submit();
            },
            "取消": function () {
                $(this).dialog("close");
            }
        },
        close: function(){
        	$(this).dialog("close");
        }
    });
    updateWindow.dialog("open");
    setAutoComplete('deptName','departmentId',getPath() + 'org/department/list/select/10',{
		labelField:'name',
		valueField:'id'
	});
    initDate("birthday");
   //往对象中赋值
   //setValue();
   
});

//初始化时间
function initDate(dateId){
	//时间控件
	$("#" + dateId ).jeDate({
		isinitVal:false,
		festival: false,
		skinCell:"jedateblue",
		isTime:false,		   
		format: 'YYYY-MM-DD'
	});
}

//修改用户信息
function updateUser(){
    //声明消息提示
    var toolTips = new Object();   
    //设置表单验证
    var validator = $("#updateUserForm").validate({    	
        rules:{
        	//phone:"required"
        },
        messages:{
        	//phone:"联系电话不能为空！"
        },
        errorPlacement: function(eror,element){
            var toolTip = createTooltip(toolTips,element.attr("id"));
            toolTip.setContent(eror.text());
            element.addClass("error-border");

        },
        success:function(label){
            var elementId = label.attr("id").substring(0,label.attr("id").length - 6);
            var toolTip = toolTips[elementId];
            $("#" + elementId).removeClass("error-border");
            toolTip.close();
            toolTip.detach();
        },	    	    	
        submitHandler:function(form){
        	loadDiv.showLoading();
            post(getPath() + "updateCurrUser",
                $("#updateUserForm").serialize(),
                function(resultObject){
            		loadDiv.hideLoading();
                    createWindow("更新成功").dialog("open");
                    updateWindow.dialog("close");
               },function(resultObject){
	        		loadDiv.hideLoading();
	        		createWindow(resultObject).dialog('open');
	        	}
            );
        }
    });
}
